<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Up extends MY_Controller {

	var $is_array = true;

	public function index()
	{
		$this->load->model("files/files_model");

		$post_arr = json_decode($this->input->raw_input_stream,$this->is_array);

		if($post_arr == NULL){
			$this->view(304,NULL,"上传数据不存在");
		}

		if( $post_arr["data"] == NULL){
			$this->view(304,NULL,"上传数据为空");
		}
		$files_data["data"] = $post_arr["data"];
		unset($post_arr["data"]);

		if( $post_arr["file"] == NULL){
			$this->view(304,NULL,"上传文件名为空");
		}
		$files_data["file"] = $post_arr["file"];
		unset($post_arr["file"]);

		if( $post_arr["ext"] == NULL) {
			$this->view(304,NULL,"上传后缀名为空");
		}
		$files_data["ext"] = $post_arr["ext"];
		unset($post_arr["ext"]);

		//@unset($post_arr["id"]); @unset($post_arr["no"]); @unset($post_arr["ctime"]); @unset($post_arr["dtime"]); @unset($post_arr["mtime"]);

		$files_data = $files_data + $post_arr;

		$return_data = $this->files_model->insert_files($files_data);

		if($return_data == NULL)
		{
			$this->view(304,NULL,"保存失败");
		}

		$this->view(200,$return_data,"上传成功");
	}

	public function lists($val = NULL,$type = "cid")
	{
		$this->load->model("files/files_model");
		if($type == NULL)
		{
			$this->view(404,NULL,"公司不能为空");
		}

		$return_data = $this->files_model->get_files_lists($val,$type);

		$this->view(200,$return_data,"成功");
	}
}
